package com.goods.business.controller;

import com.goods.business.service.ProductListService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author liangliang
 * @Date 2021/11/9 13:51 Administrator
 * @Description
 * 物资类别
 */
@RestController
@RequestMapping("/business/product")
public class ProductListController {

    @Autowired
    private ProductListService productListService;


    @GetMapping("/findProductList")
    public ResponseBean findProductList(@RequestParam("pageNum")Integer pageNum,
                                        @RequestParam("pageSize")Integer pageSize,
                                        @RequestParam Map map){
        PageVO<ProductVO> productVOPageVO=productListService.findProductList(pageNum,pageSize,map);
        return ResponseBean.success(productVOPageVO);
    }

    /**
     * 添加物资资料
     * @param
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        productListService.add(productVO);
        return ResponseBean.success();
    }

    /**
     * 编辑物资用于做修改时的数据回显
     * @return
     */
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductVO productVO=productListService.edit(id);
        return ResponseBean.success(productVO);
    }

    /**
     * 修改物资资源
     * @param id
     * @param productVO
     * @return
     */
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody ProductVO productVO){
        productListService.update(id,productVO);
        return ResponseBean.success();
    }

    /**
     * 将物资资源移到回收站
     * @param id
     * @return
     */
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        productListService.remove(id);
        return ResponseBean.success();
    }

    /**
     * 将回收站中的东西恢复
     * @param id
     * @return
     */
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
     productListService.back(id);
     return ResponseBean.success();
    }

    /**
     * 将回收站的东西删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
    productListService.delete(id);
    return ResponseBean.success();
    }

    /**
     * 通过审核
     * @param id
     * @return
     */
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
    this.back(id);
    return ResponseBean.success();
    }

    /**
     * 分页展示，入库时的物资资料数据
     * @param pageNum
     * @param pageSize
     * @param map
     * @return
     */
    @GetMapping("/findProducts")
    public ResponseBean findProducts(@RequestParam("pageNum")Integer pageNum,
                                     @RequestParam("pageSize")Integer pageSize,
                                     @RequestParam Map map){
        PageVO<ProductVO> productVOPageVO=productListService.findProducts(pageNum,pageSize,map);
        return ResponseBean.success(productVOPageVO);

    }

    /**
     * 物资库存
     * @param pageNum
     * @param pageSize
     * @param map
     * @return
     */
    @GetMapping("/findProductStocks")
    public ResponseBean findProductStocks(@RequestParam("pageNum")Integer pageNum,
                                      @RequestParam("pageSize")Integer pageSize,
                                      @RequestParam Map map){
        PageVO<ProductStockVO> productStockVOPageVO=productListService.findProductStocks(pageNum,pageSize,map);
        return ResponseBean.success(productStockVOPageVO);
    }
}
